<?php

namespace app\api\validate;

use think\Validate;

/**
 *  支付订单验证器
 */
class Order extends Validate
{

    // 定义验证规则
    protected $rule = [
        'version|版本号' => 'require|eq:1.0',
        'merchant_id|商户号' => 'require',
        'merchant_order_id|商户订单号' => 'require|alphaNum|length:5,32',
        'app_id|应用ID' => 'require',
        'cash|金额' => 'require|float|egt:0.01|length:1,8',
        'type|支付类型' => 'require',
        'trade_type|交易类型' => 'require',
        'body|商品名称' => 'require|length:1,50',
        'name|姓名' => 'require|length:1,50',
        'id_card|身份证号' => 'require|length:1,50',
        'mobile|手机号' => 'require|length:1,50',
        'return_url|支付完成调转地址' => 'require|length:1,300',
        'notify_url|支付成功服务端通知地址' => 'require|length:1,300',
        'ip|IP地址' => 'require|ip',
        'user_id|用户ID' => 'require|number|length:1,20',
        'channel_id|渠道ID' =>  'require|length:1,50',
        'business_type|业务类型' => 'requireIf:type,wangyin|length:1,20',
        'bank_code|银行编号' => 'requireIf:type,wangyin|length:1,20',
        'format|格式' => 'require',
        'sign_type|签名类型' => 'require',
        'extra|商户自定义备注' => 'length:0,300',
        'start_time|创建时间' => 'require|number|length:10,11',
        'random_string|随机字符串' => 'require',
        'sign|签名' => 'require',
        'class|查询类型' => 'length:0,10',
        'order_id|平台订单号' => 'length:1,50',
    ];
    // 定义验证提示
    protected $message = [
        'class.require' => '查询类型不能为空',
    ];

    // 定义场景
    //    protected $scene = [
    //        'order' => ['order_id' => 'require', 'start_time' => 'require', 'sign' => 'require'],
    //        'query' => ['merchant_id', 'merchant_order_id', 'class', 'start_time', 'random_string', 'sign'],
    //        'returl' => ['order_id' => 'require'],
    //    ];
    // 验证场景定义
    public function sceneQuery()
    {
        return $this->only(['merchant_id', 'merchant_order_id', 'class', 'start_time', 'random_string', 'sign'])
            ->append('class', 'require');
    }

    // 验证场景定义
    public function sceneOrder()
    {
        return $this->only(['order_id', 'start_time', 'sign'])
            ->append('order_id', 'require');
    }

    // 验证场景定义
    public function sceneReturl()
    {
        return $this->only(['order_id'])
            ->append('order_id', 'require');
    }
}
